General
TPlusMemo offers collapsible blocks functionality whereby sections of text content can be collapsed and later expanded. A collapsible block starts at a given position in the memo content and ends on a line further down in the memo. When collapsed, only the first line of the block is shown; all following lines that are part of the block, including the last one, become hidden.
A special accessory component, TpmCollapseHandler, can be used to give visual cue about collapsible sections in the form of a colored vertical bar in the left margin at the proper vertical level. It also permits the user to collapse and expand blocks by clicking on a square at the top left of the block. The mouse cursor changes when above that square, indicating its purpose. Below is a picture of the visual aspect of collapsible blocks with TpmCollapseHandler:

There are two ways to define collapsible blocks in TPlusMemo. Dynamic sections (also called "start-stop sections") can be made collapsible, by defining the appropriate attributes at design time or at run time. Whenever a start-stop section is found by TPlusMemo, it will be made collapsible automatically if that section definition includes the collapsible attribute. Such a block is said to be a "dynamic collapsible block". The collapsible attribute of affected text disappears when the start-stop section is destroyed following user edition or program action.
The second way to define collapsible blocks is done by the application calling one of the block definition methods described below. Such blocks are said to be static, and keep their collapsible attributes until the block is completely deleted or a call is made to a block elimination method.
Collapsible blocks can be nested up to 15 levels. Note that in the current release (v6.6b), blocks can be collapsed only if WordWrap is False and Alignment is taLeftJustify. It is recommended to not mix dynamic and static collapsible blocks in a TPlusMemo. This can result in incorrect behavior when attempting to collapse or expand them.
Collapsible blocks should not be confused with the "columnar block selection functions" that are available in TPlusMemo when property Options includes pmoBlockSelection.
Making parts of the text content collapsible
There are two ways to get dynamic collapsible blocks:
- Using TExtHighlighter accessory and defining some start-stop keys with the Collapsible attribute. Resulting dynamically highlighted sections will be collapsible. This can be done at design time with the Start-Stop Keys editor or at run time with method TExtHighlighter.StartStopKeys.AddExStartStopKey, by including ssoCollapsible in parameter ssOptions.
- Using method TPlusMemo.SetDynStyle, passing parameter Collapsible with a value of True. This enables to make a dynamic collapsible section out of arbitrary positions. Those sections can be reset to a non collapsible state by calling ClearStyle or ClearStyleRange.
Static blocks can be defined with two methods of TPlusMemo:
- Method TPlusMemo.MakeSelCollapsible, which makes the current selection a static collapsible block. That block can be returned non collapsible by using TPlusMemo.RemoveCollapsibleBlock or TPlusMemo.RemoveSelCollapsible. If the selection does not encompass more than one line, no block is defined;
- Method TPlusMemo.MakeCollapsibleBlock, which makes a static collapsible block out of arbitrary paragraph ranges. That block can also be returned non collapsible by using TPlusMemo.RemoveCollapsibleBlock or TPlusMemo.RemoveSelCollapsible. The state of a static collapsible block can be queried with method GetBlocksStates.
Collapsing and Expanding blocks
Collapsible blocks can be collapsed programmatically by calling TPlusMemo.CollapseSel, CollapseBlock or CollapseAll. They can be expanded by the control of your application with the help of TPlusMemo.ExpandSel, ExpandBlock or ExpandAll.
They can also be operated directly by the user if you use a TpmCollapseHandler component as property TPlusMemo.CollapseHandler, as discussed above.
As mentioned above, with the current release blocks can be collapsed only if WordWrap is False and Alignment is taLeftJustify.